package Controller;

import Model.Scenario;
import java.io.FileWriter;
import java.io.IOException;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

/**
 * ScenarioExecutor class is responsible for scenario serialization to XML
 * @author V3nom
 */
public class ScenarioExecutor {

    private JAXBContext context;
    private Marshaller marshaller;

    public ScenarioExecutor() {
        try {
            context = JAXBContext.newInstance(Scenario.class);
            marshaller = context.createMarshaller();
        } catch (JAXBException ex) {
            System.out.println(ex);
        }
    }

    /*
     * Takes scenario object and serializes it with all dependencies
     * @param scenario
     */
    public void execute(Scenario scenario) throws JAXBException, IOException {
            marshaller.marshal(scenario, new FileWriter(scenario.getAlias() + ".xml"));
    }
}
